package com.test.socket;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ThreadExample implements Runnable{
	
	private String greeting;//message to print to console
	
	public ThreadExample(String greeting){
		this.greeting = greeting;
	}
	@Override
	public void run() {
	while(true){
		System.out.println(Thread.currentThread().getName()+": "+greeting);
		try {
			//sleep 0 to 100 milliseconds
			TimeUnit.MILLISECONDS.sleep((long) (Math.random()*1000));
		} catch (InterruptedException e) {
			// TODO: handle exception
		}
	}
		
	}
	
	public static void main(String[] args){
		ExecutorService exec  = Executors.newCachedThreadPool();
		exec.execute(new ThreadExample("hello"));
		exec.execute(new ThreadExample("Aloha"));
		exec.execute(new ThreadExample("ciao"));
	}

}
